package com.jcroke.DACGraph;
/**
 * @author jcroke
 */
import java.util.ArrayList;

import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.traverse.TopologicalOrderIterator;

import com.jcroke.DACGraph.DAC.DACClient;
import com.jcroke.DACGraph.utils.GraphVizDotGenerator;

public class RDFDriver {

	public static DACClient dac;
	public static String dataSet = "exp/experiment";
	public static RDFData rdf;

	public static void main(String[] args) {
		dac = new DACClient("localhost", 8080);

		rdf = new RDFData(dac, dataSet);
		rdf.buildGraph();
		
		if (rdf.cyclesDetected()) {
			System.out.println("cycles detected");
			ArrayList<Pnode> cycles = rdf.getCycles();
			for (Pnode cycle : cycles ) {
				System.out.println(cycle.toString());
			}
		} else {
			TopologicalOrderIterator<Pnode, DefaultEdge> orderIterator = rdf.getIterator();
			System.out.println("\nOrdering:");
			Pnode v;
			while (orderIterator.hasNext()) {
				v = orderIterator.next();
				System.out.println(Pnode.substrIRI(v.getIRI()));
			}
		}
		new GraphVizDotGenerator("/home/jcroke/graphviz/foo.dot",rdf.getDirectedGraph()).createDotFile();
	}
}
